<template>
<!--添加商品管理-->
  <div class="container">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>添加商品</span>
        <el-button style="float: right; padding: 3px 0" type="text" @click="back">返回</el-button>
      </div>
      <el-form ref="addForm" v-model="addGoodForm" label-width="120px">
        <el-form-item label="品牌名称">
          <el-input v-model="addGoodForm.name" style="width: 300px"></el-input>
        </el-form-item>
        <el-form-item label="商品图片">
          <el-upload
            action="/oss/img"
            :file-list="fileList"
            list-type="picture-card"
            name="object"
            :on-success="uploadSuccess"
            :on-preview="handlePictureCardPreview"
            :on-remove="handleRemove">
            <i class="el-icon-plus"></i>
          </el-upload>
          <el-dialog :visible.sync="dialogVisible">
            <img width="100%" :src="this.dialogImg" alt="">
          </el-dialog>
        </el-form-item>
        <el-form-item label="品牌类型">
          <el-radio-group v-model="addGoodForm.type">
            <el-radio label="1">国产</el-radio>
            <el-radio label="0">进口</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">添加</el-button>
          <el-button @click="back">取消</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
import { addBranList } from '@/api/goodBrand'

export default {
  name: 'addGoodBrand',
  data(){
    return{
      addGoodForm:{},
      //上传图片数据
      fileList:[],
      dialogVisible:false,
      dialogImg:""
    }
  },
  methods:{
    back(){
      this.$store.dispatch('tagsView/delVisitedView', this.$route)
      this.$router.push('/goods/goodbrand')
    },
    uploadSuccess(file, fileList) {
      this.fileList.push({url:fileList.response.data})
    },
    //移除上传图片数据
    handleRemove(file, fileList) {
      this.fileList=fileList
    },
    handlePictureCardPreview(file) {
      this.dialogVisible = true;
      this.dialogImg=file.url
    },
    onSubmit(){
      addBranList({
        name:this.addGoodForm.name,
        type:this.addGoodForm.type,
        image: this.fileList[0].url
      }).then(()=>{
        this.$message.success('添加成功')
        this.back()
      })
    }
  }
}
</script>

<style scoped lang="scss" scoped>
.container{
  padding: 20px;
}
</style>
